
package com.yimixian.app.store;

import com.yimixian.app.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class SectionAreaItemView extends FrameLayout {

    @InjectView(R.id.orange_band)
    View mOrangeBand;
    @InjectView(R.id.white_band)
    View mWhiteBand;
    @InjectView(R.id.section_name_text)
    TextView mSectionNameText;

    private String mSectionName;

    public SectionAreaItemView(Context context) {
        super(context);
        initSectionItemView();
    }

    public SectionAreaItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initSectionItemView();
    }

    public SectionAreaItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initSectionItemView();
    }

    private void initSectionItemView() {
        LayoutInflater.from(getContext()).inflate(R.layout.section_area_item_view, this);
        ButterKnife.inject(this);
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                getResources().getDimensionPixelSize(R.dimen.section_area_item_height));
        setLayoutParams(params);
    }

    public void init(String sectionName) {
        mSectionNameText.setText(sectionName);
        mSectionName = sectionName;
    }

    public String getSectionName() {
        return mSectionName;
    }

    public void setClicked(boolean clicked) {
        mWhiteBand.setVisibility(clicked ? View.VISIBLE : View.INVISIBLE);
        mOrangeBand.setVisibility(clicked ? View.VISIBLE : View.INVISIBLE);
        mSectionNameText.setTextColor(clicked ? getResources().getColor(R.color.ymx_orange) : 0xff333333);
        setBackgroundColor(clicked ? 0xffffffff : 0x00000000);
    }
}
